import com.wr.comsumer.ComsumerServer;
import com.wr.filter.TPMonitorFilter;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 王瑞
 * @description: TODO
 * @date 2020/4/16  15:09
 */
public class ComsumerMain {

    private static ThreadPoolExecutor poolExecutor =
            new ThreadPoolExecutor(3,
                    3,
                    5,
                    TimeUnit.SECONDS,
                    new ArrayBlockingQueue<Runnable>(10000),
                    new ThreadPoolExecutor.DiscardPolicy());

    public static void main(String[] args) throws InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ComsumerConfig.class);

        context.start();

        final ComsumerServer comsumerServer = context.getBean(ComsumerServer.class);

        Runnable runnableA =new Runnable() {
            @Override
            public void run() {
                while (true){
                    String lagouA = comsumerServer.getMethodA("lagouA");
                    System.out.println(lagouA);
                }
            }
        };
        Runnable runnableB =new Runnable() {
            @Override
            public void run() {
                while (true){
                    String lagouB = comsumerServer.getMethodB("lagouB");
                    System.out.println(lagouB);
                }
            }
        };
        Runnable runnableC =new Runnable() {
            @Override
            public void run() {
                while (true){
                    String lagouC = comsumerServer.getMethodC("lagouC");
                    System.out.println(lagouC);
                }
            }
        };

        poolExecutor.execute(runnableA);
        poolExecutor.execute(runnableB);
        poolExecutor.execute(runnableC);

    }


    @EnableDubbo
    @Configuration
    @PropertySource("classpath:dubbo-comsumer.properties")
    @ComponentScan(basePackages = "com.wr.comsumer")
    static class ComsumerConfig {}
}
